﻿using MediatR;
using Microsoft.Extensions.Configuration;
using S.Common.helper;
using S.Initial.API.Application.Command.BreedingMothers;
using S.Initial.Infrastructure.Interface;
using static S.Initial.API.Application.Command.BreedingMothers.CreateBreedingMothersCommand;

namespace S.Initial.API.Application.CommandHandlers.BreedingMothers
{
    /// <summary>
    /// 批量删除
    /// </summary>
    public class DeletedAllinitialCommandHandler : IRequestHandler<DeletedAllinitialCommand, int>
    {
        private readonly IBreedingMothersRepository breeding;
        private readonly IConfiguration configuration;
        public DeletedAllinitialCommandHandler(IBreedingMothersRepository breeding, IConfiguration configuration)
        {
            this.breeding = breeding;
            this.configuration = configuration;
        }
        public Task<int> Handle(DeletedAllinitialCommand request, CancellationToken cancellationToken)
        {
            UpdateEarTag updateEarTag = new UpdateEarTag();
            request.IntAll.ForEach(a =>
            {
                updateEarTag = new UpdateEarTag()
                {
                    earTag = new List<string> { a },
                    uflag = 2,
                    uState = 1,
                };
            });
            //修改档案在线状态成待入场
            HttpClientHelper.PutDataResponse($"{configuration.GetValue<string>("Gateway")}/achs/api/SheepFileModel/SheepFileUpdateStatePL", updateEarTag);
            return breeding.DeleteAllBreedingmothers(request.IntAll);
        }

    }
}
